<template>
  <xy-page>
    <div class="viewShare">
      <el-form style="display:inline-block" class="fl">
        <el-form-item label="标题:" :label-width="labwidth">
          <el-input v-model="title" maxlength="30" class="w300"></el-input>
          <span style="color:#ccc;height:40px;line-height:40px;">{{title.length}}/30</span>
        </el-form-item>
        <el-form-item label="简介:" :label-width="labwidth">
          <el-input
            type="textarea"
            maxlength="120"
            v-model="introduce"
            class="w300"
            :rows="4"
            resize="none"
          ></el-input>
          <span style="color:#ccc;height:95px;line-height:95px;">{{introduce.length}}/120</span>
        </el-form-item>
        <el-form-item label :label-width="labwidth">
          <el-button type="primary" @click="saveWeixin">保存</el-button>
        </el-form-item>
      </el-form>
      <img src="/static/images/ipone.png" style="width:600px; left:440px;position:absolute;">
      <div class="share-box">
        <div class="titles">分享预览</div>
        <div class="share-box-content">
          <div class="graycolor">分享给好友:</div>
          <div>
            <img
              src="/static/images/user-default.png"
              class="fl"
              style="width:30px;height:30px;line-height:0px;"
            >
            <div class="share-friend">
              <div class="share-friend-title" style="width: 100%;">{{title}}</div>
              <div class="share-circle">
                <div class="graycolor introduce-title ellipsis">{{introduce}}</div>
                <img v-if="coverImg" :src="coverImg" class="introduceimg introduceimg-friend">
                <img
                  v-else
                  src="/static/images/default-polyv-logo.png"
                  class="introduceimg introduceimg-friend"
                >
              </div>
            </div>
          </div>

          <div class="graycolor mgt20">分享到朋友圈:</div>
          <div>
            <img
              src="/static/images/user-default.png"
              class="fl"
              style="width:30px;height:30px;line-height:0px;"
            >
            <div class="share-friend-title" style="margin-left:35px;font-size:12px;">微信呢称</div>
            <div class="share-friend">
              <div class="share-circles">
                <img v-if="coverImg" :src="coverImg" class="introduceimg">
                <img v-else src="/static/images/default-polyv-logo.png" class="introduceimg">
                <span class="mgl20 share-circel-title">{{title}}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </xy-page>
</template>

<script>
export default {
  data() {
    return {
      labwidth: '100px',
      title: '',
      introduce: '',
      channelId: '',
      appId: '',
      coverImg: '' // 分享图片
    };
  },
  methods: {
    saveWeixin() {
      this.$postStream("/admin/instance/ccb/polyv/weixin/update.do", {
        data: {
          appId: this.appId,
          channelId: this.channelId,
          weixinShareDesc: this.introduce,
          weixinShareTitle: this.title
        },
        success: res => {
          if (res.success) {
            this.$message.success("保存成功!")
          } else {
            res.code == 50001?this.$message.error(res.message):this.$message.error('保存失败!')
          }
        }
      })
    },
    getWeixin() {
      this.$postStream("/admin/instance/ccb/polyv/weixin/get.do", {
        data: {
          appId: this.appId,
          channelId: this.channelId
        },
        success: res => {
          if (res.success) {
            this.title = res.object.weixinShareTitle
            this.introduce = res.object.weixinShareDesc
            this.coverImg = res.object.coverImg || ""
            if (res.object.coverImg == "/assets/wimages/pc_images/logo.png") {
              this.coverImg = ""
            }
          } else {
            this.$message.error("获取失败!")
          }
        }
      })
    }
  },
  mounted() {
    this.channelId = sessionStorage.getItem("channelId")
    this.appId = sessionStorage.getItem("appId")
    this.getWeixin()
  }
};
</script>

<style lang="scss" scoped>
.viewShare {
  position: relative;
  .share-box {
    position: absolute;
    background: linear-gradient(180deg,#e8ebf5,#f2f2f2);
    left: 626px;
    top: 93px;
    float: left;
    height: 412px;
    width: 228px;
    .share-box-content {
      position: relative;
      margin: 0 10px;
      width: 210px;
    }
    .share-friend {
      position: relative;
      width: 173px;
      padding: 10px;
      display: inline-block;
      background: #fff;
      line-height: 20px;
      margin: 5px 0 0 5px;
      .share-friend-title {
        line-height: 16px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        vertical-align: top;
        font-size: 12px;
      }
      .share-circel-title {
        margin: 5px 0;
        line-height: 16px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        width: 107px;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        vertical-align: top;
        font-size: 12px;
      }
    }
    .graycolor {
      font-size: 12px;
    }
    .introduce-title {
      width: 106px;
      float: left;
      word-wrap: break-word;
      -webkit-line-clamp: 2;
    }
    .introduceimg {
      width: 40px;
      height: 40px;
      margin: 3px;
      border: 1px solid rgb(192, 185, 175);
      position: relative;
      float: left;
      vertical-align: top;
      word-wrap: break-word;
    }
    .introduceimg-friend {
      float: right;
    }
  }
  .titles {
    display: block;
    height: 40px;
    line-height: 40px;
    &::before {
      content: " ";
      width: 5px;
      height: 30px;
      background: #409eff;
      display: inline-block;
      vertical-align: top;
      margin: 5px 10px;
    }
  }
  .ellipsis {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3; /*超出3行部分显示省略号，去掉该属性 显示全部*/
    -webkit-box-orient: vertical;
  }
}
</style>
